import Vue from 'vue'
import VueRouter from 'vue-router'

const Login = () => import(`@/views/Login`)
const Home = () => import(`@/views/system/Home`)

const Graphical = () => import('../views/system/Graphical')
const Publish = () => import('../views/system/Publish')
const ManageArticle = () => import('../views/system/ManageArticle')
const ManageComment = () => import('../views/system/ManageComment')
const Label = () => import('../views/system/Label')
const ManageDocument = () => import('../views/system/ManageDocument')
const System = () => import('../views/system/System')
//   前台的路由
const Index = () => import("../components/Index")
const AboutMe = () => import("../components/AboutMe")
const MessageBoard = () => import("../components/MessageBoard")
const SuiBi = () => import("../components/SuiBi")
Vue.use(VueRouter)

const routes = [
    {
        path: `/`,
        redirect: `/login`
    },
    {
        path: '/login',
        name: 'Login',
        component: Login
    },
    {
        path: '/home',
        name: 'Home',
        component: Home,
        children:[
            //    图形统计
            {
                path: '/graphical',
                name: 'graphical',
                component: Graphical

            },
            //    发表文章
            {
                path: '/publish',
                name: 'Publish',
                component: Publish

            },
            //    管理文章
            {
                path: '/managearticle',
                name: 'ManageArticle',
                component: ManageArticle

            },
            //    管理评论
            {
                path: '/managecomment',
                name: 'ManageComment',
                component: ManageComment

            },
            //    标签
            {
                path: '/label',
                name: 'Label',
                component: Label

            },
            //    文件上传
            {
                path: '/managedocument',
                name: 'ManageDocument',
                component: ManageDocument

            },
            //    系统设置
            {
                path: '/system',
                name: 'System',
                component: System

            },
        ]

    },

//    前台的路由
    {
        path: '/index',
        name: 'Index',
        component: Index
    },
    {
        path: '/aboutMe',
        name: 'AboutMe',
        component: AboutMe
    },
    {
        path: '/messageBoard',
        name: 'MessageBoard',
        component: MessageBoard
    },
    {
        path: '/suiBi',
        name: 'SuiBi',
        component: SuiBi
    }
]

const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes
})
//挂载路由导航守卫
// router.beforeEach((to, from, next) => {
//     if (to.path === "/login" || to.path === "/") return next();
//     const token = window.sessionStorage.getItem("authorization")
//     if (!token) return next('/login')
//     next()
// })
export default router
